package arthur.dy.lee.distrlock;

import org.redisson.Redisson;
import org.redisson.api.RLock;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;

/**
 * Created by Administrator on 2017/8/14.
 */
public class RedisLockTest {

    public static void main(String[] args) throws InterruptedException {
        Config config = new Config();
        config.useSentinelServers().addSentinelAddress("127.0.0.1:6479", "127.0.0.1:6489").setMasterName("master")
                .setPassword("password").setDatabase(0);
        RedissonClient redissonClient = Redisson.create(config);
        //RLock lock = redissonClient.getLock("LOCKER_PREFIX" + "resourceName");

        RLock lock = redissonClient.getLock("test_lock");
        try {
            boolean isLock = lock.tryLock();
            if (isLock) {
                //doBusiness();
            }
        } catch (Exception e) {
        } finally {
            lock.unlock();
        }


        /*RedissonClient redisson= redissonConnector.getClient();
        RLock lock = redisson.getLock(LOCKER_PREFIX + resourceName);
        boolean success = lock.tryLock(100, lockTime, TimeUnit.SECONDS);*/
    }
}
